
var detailData;
var siteBookTable;
function getsiteBookList() {
    if (typeof siteBookTable !== 'undefined') {
        siteBookTable.fnPageChange('first');
        return;
    }
    siteBookTable = $("#siteBookList").DataTable({
        "sAjaxSource": _path + "/siteBook/queryByPage",     //服务端
        "fnServerParams": function (aoData) {               //ajax请求参数
            aoData.push(
                { "name": "name", "value": $("#name").val()||'' },
                { "name": "fromDate", "value": $("#fromDate").val() },
                { "name": "toDate", "value": $("#toDate").val() }
            );
        },
        "fnServerData": function(sUrl, aoData, fnCallback) {
            var data = new Array();
            for(var i in aoData)
                data.push(aoData[i].name + '=' + aoData[i].value);
            $.ajax( {
                "type": "POST",
                "url": sUrl,
                "dataType": "json",
                "data": data.join('&'),
                "success": function(resp) {
                    detailData = resp.dataList;
                    fnCallback(resp);
                }
            });
        },
        "sServerMethod": "POST",    //请求方式
        "sAjaxDataProp": "dataList",//后台返回数据名
        "aoColumns": [
            { "sTitle": "姓名", "sWidth": "3%", "mData": "name" },
            { "sTitle": "标题", "sWidth": "6%", "mData": "title" },
            { "sTitle": "联系电话", "sWidth": "6%", "mData": "phone" },
            { "sTitle": "用户IP", "sWidth": "6%", "mData": "ip" },
            { "sTitle": "email", "sWidth": "6%", "mData": "email" },
            { "sTitle": "留言内容", "sWidth": "6%", "mData": function(data){
            	if(data.content.length<14){
            		return "<p>"+data.content+"</p>";
            	}else{
            		return "<p title='"+data.content+"'>"+(data.content).substring(0,18)+"...</p>";
            	}
            }},
            { "sTitle": "留言时间", "sWidth": "6%", "mData": "createTime" },
//            { "sTitle": "审核状态", "sWidth": "6%", "mData": "status"},
            { "sTitle": "操作", "sWidth": "5%",
                "mData": function (data) {
                	 var html = new Array();
                	 if(data.status==1){
		            	 html.push('<a href="javascript:oper(1,\'' + data.id + '\');" id="btnA" class="btn  btn-xs green">');
		                 html.push('<i class="fa fa-check-square-o" title="审核通过"></i> </a>');
                	 }
                     if(data.status==0){
	                     html.push('<a href="javascript:oper(2,\'' + data.id + '\');" id="btnB" class="btn  btn-xs blue">');
	                     html.push('<i class="fa fa-times-circle-o" title="审核不通过"></i> </a>');
                     }
                	 html.push('&nbsp;<a href="' + _path + '/siteBook/delete/' + data.id + '" id="btnDel" class="btn  btn-xs red">');
                     html.push('<i class="fa fa-trash-o" title="删除"></i> </a>');
                     return html.join('');
                }
            }
        ]
    });
}

function oper(type, id) {
    App.ajax(_path + "/siteBook/oper", "id=" + id + "&type=" + type, function (data) {
        switch (data.statusCode) {
            case 200 :
                alert("操作成功！");
                break;
            case 500 :
                alert(data.info);
                break;
            default :
                alert("操作失败！");
                break;
        }
        window.location.href = _path + "/siteBook/list";
    });
}